package leetcode.editor.offer;

// 剑指 Offer 65. 不用加减乘除做加法
// https://leetcode.cn/problems/bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof/
class BuYongJiaJianChengChuZuoJiaFaLcof {
    public static void main(String[] args) {
        Solution solution = new BuYongJiaJianChengChuZuoJiaFaLcof().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int add(int a, int b) {
            // 当进位为0时停止循环
            while (b != 0) {
                int c = (a & b) << 1;  // 计算进位
                a ^= b; // a=非进位(异或：同为0，异为1)
                b = c;  // b=进位
            }

            return a;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
